#!/usr/bin/env python
# @Date    : 2022-04-25
# @Author  : Bright (brt2@qq.com)
# @Link    : https://gitee.com/brt2
# @Version : 0.1.0

import os.path
import sys
from fastapi import FastAPI as Application

def app_run(app, *args, **kwargs):
    assert isinstance(app, str), "使用uvicorn(FastAPI)启动服务，需要传入app字符串"
    import uvicorn
    filename_caller = sys._getframe(2).f_code.co_filename
    basename_caller = os.path.splitext(filename_caller)[0]
    uvicorn_app = f"{basename_caller}:{app}"
    # print(">>>", uvicorn_app)
    return uvicorn.run(uvicorn_app, *args, **kwargs)

def make_app(app_name, **kwargs):
    kwargs["docs_url"] = "/swagger"  # 设置openapi路径
    app = Application(**kwargs)
    return app

from fastapi.responses import RedirectResponse
redirect=RedirectResponse
# def redirect(*args, **kwargs):
#     return RedirectResponse(*args, **kwargs)
